package com.sky.controller.admin;

import com.sky.context.BaseContext;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController("adminOrderController")
@RequestMapping("/admin/order")
@Api(tags = "订单管理相关接口")
public class OrderController {

    @Autowired
    OrderService orderService;


    /**
     * 查询用户订单
     * @param ordersPageQueryDTO
     * @return
     */
    @ApiOperation("搜索订单")
    @GetMapping("/conditionSearch")
    public Result<PageResult> conditionSearch(OrdersPageQueryDTO ordersPageQueryDTO) {
        log.info("查询用户订单");
        PageResult pageResult = orderService.conditionSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }

    /**
     * 各个状态的订单统计
     * @return
     */
    @ApiOperation("各个状态订单数量统计")
    @GetMapping("/statistics")
    public Result<OrderStatisticsVO> statisticsResult() {
        OrderStatisticsVO orderStatisticsVO = orderService.statisticsResult();
        return Result.success(orderStatisticsVO);
    }

    /**
     * 查看订单详情
     * @param id
     * @return
     */
    @ApiOperation("查看订单详情")
    @GetMapping("/details/{id}")
    public Result<OrderVO> OrderMessage(@PathVariable Long id) {
        OrderVO orderVO = orderService.checkOrder(id);
        return Result.success(orderVO);
    }

    /**
     * 接单
     * @param order
     * @return
     */
    @ApiOperation("接单")
    @PutMapping("/confirm")
    public Result getOrder(@RequestBody Orders order) {
        orderService.getOrder(order);
        return Result.success();
    }

    /**
     * 拒单
     * @param order
     * @return
     */
    @ApiOperation("拒单")
    @PutMapping("/rejection")
    public Result rejectionOrder(@RequestBody Orders order) {
        orderService.rejectionOrder(order);
        return Result.success();
    }

    /**
     * 取消订单
     * @param order
     * @return
     */
    @ApiOperation("取消订单")
    @PutMapping("/cancel")
    public Result adminCancelOrder(@RequestBody Orders order) {
        orderService.adminCancelOrder(order);
        return Result.success();
    }

    /**
     * 派送订单
     * @param id
     * @return
     */
    @ApiOperation("派送订单")
    @PutMapping("/delivery/{id}")
    public Result adminCancelOrder(@PathVariable Long id) {
        orderService.sendOrder(id);
        return Result.success();
    }

    /**
     * 完成订单
     * @param id
     * @return
     */
    @ApiOperation("完成订单")
    @PutMapping("/complete/{id}")
    public Result completeOrder(@PathVariable Long id) {
        orderService.completeOrder(id);
        return Result.success();
    }



}
